package com.example.demo.controller;

import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    //编程式事务
    @Autowired
    private DataSourceTransactionManager transactionManager;
    @Autowired
    private TransactionDefinition transactionDefinition;
    @RequestMapping("/del")
    public int del(Integer id){
        if (id != null && id>0){
            //1.开启事务
            TransactionStatus transactionStatus
                    = transactionManager.getTransaction(transactionDefinition);
            //业务操作，删除用户

        }
        return 0;
    }
}
